var express = require('express');
var app = express();

app.all('*',function(req,res,next){   //
    res.header("Access-Control-Allow-Origin","*");
    res.header("Access-Control-Allow-Headers","X-Request-With");
    res.header("Access-Control-Allow-Methods","PUT,POST,GET,DELETE,OPTIONS");
    res.header("X-Powered-By",'3.2.1');
    res.header("Content-Type","application/json;charset=utf-8");
    next();
});

var infor = [   //传前端的数据
    {
        name:'ZZSB',
        age:20,
        sex:'男',
        hobby:'Adidas'
    },
    {
        name:'ZZSB',
        age:21,
        sex:'男',
        hobby:'Nick'
    },
    {
        name:'ZZSB',
        age:22,
        sex:'男',
        hobby:'绿水鬼'
    },
    {
        name:'ZZSB',
        age:23,
        sex:'男',
        hobby:'奔驰S'
    },
    {
        name:'ZZSB',
        age:24,
        sex:'男',
        hobby:'美女豪车'
    },
]

app.get('/api',function(req,res){   //配置接口api
    res.status(200),
    res.json(infor)
})

// 配置服务端口
var server = app.listen(3002,function(){
    var host = server.address().address;
    var port = server.address().port;
    console.log('listen at http://%s:%s',host,port)
})